﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace CommonSLT
{
	public partial class GridControl : DevExpress.XtraEditors.XtraUserControl
	{
		#region variants
		public string sortColumn = "";
		public string orderByExpression = "ASC";
		public event EventHandler<EventArgs> OnInColumn_Click = null;
		public event EventHandler<EventArgs> OnRow_DoubleClick = null;
		public event EventHandler<EventArgs> OnGroupColumn_DoubleClick = null;
		public event EventHandler<EventArgs> OnEmptyArea_DoubleClick = null;
		public event DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler OnFocusedRowChanged = null;
		#endregion variants
		//=========================================================================================

		#region control
		public GridControl()
		{
			InitializeComponent();
			this.grvControl.MouseDown += new MouseEventHandler(grvControl_MouseDown);
			this.grvControl.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(grvControl_FocusedRowChanged);
		}
		#endregion control
		//=========================================================================================

		#region grid options
		public void AllowSort(bool allow)
		{
			this.grvControl.OptionsCustomization.AllowSort = allow;
		}

		public void MultiSelect(bool multiSelect)
		{
			this.grvControl.OptionsSelection.MultiSelect = multiSelect;
		}

		public void AllowCellMerge(bool allow)
		{
			this.grvControl.OptionsView.AllowCellMerge = allow;
		}

		public void SetViewCaption(string content)
		{
			if (content == null || content == "")
				this.grvControl.OptionsView.ShowViewCaption = false;
			else
			{
				this.grvControl.OptionsView.ShowViewCaption = true;
				this.grvControl.ViewCaption = content;
			}
		}

		public void ShowGroupPanel(bool show)
		{
			this.grvControl.OptionsView.ShowGroupPanel = show;
		}
		#endregion grid options
		//=========================================================================================

		#region SETTERS
		public void SetDataSource(object dataSource)
		{
			int currFocusedRowHandle = -1;
			try
			{
				currFocusedRowHandle = grvControl.FocusedRowHandle;
			}
			catch
			{
			}

			try
			{
				this.grdControl.DataSource = dataSource;
			}
			catch
			{
			}

			try
			{
				if (currFocusedRowHandle != -1)
					this.grvControl.FocusedRowHandle = currFocusedRowHandle;
			}
			catch
			{
			}

			try
			{
				this.grvControl.BestFitColumns();
			}
			catch
			{
			}
		}

		public void SetFocusedRowHandle(int rowHandle)
		{
			this.grvControl.FocusedRowHandle = rowHandle;
		}

		public void SetCellValue(int rowHandle, string fieldName, object _value)
		{
			this.grvControl.SetRowCellValue(rowHandle, fieldName, _value);
		}

		public void SetCustomSummaryValue(string fieldName, object value)
		{
			this.grvControl.Columns[fieldName].SummaryItem.DisplayFormat = value.ToString();
		}

		public void SetColumnAutoWidth(bool value)
		{
			this.grvControl.OptionsView.ColumnAutoWidth = value;
		}
		#endregion SETTERS
		//=========================================================================================

		#region GETTERS
		public int GetRowCount()
		{
			return this.grvControl.RowCount;
		}

		public object GetDataSource()
		{
			return this.grdControl.DataSource;
		}

		public int GetFocusedRowHandle()
		{
			return this.grvControl.FocusedRowHandle;
		}

		public object GetCellFocusedValue()
		{
			return this.grvControl.FocusedValue;
		}

		public DataRow GetDataRow(int rowHandle)
		{
			return this.grvControl.GetDataRow(rowHandle);
		}

		public DataRow GetFocusedDataRow()
		{
			return this.grvControl.GetFocusedDataRow();
		}

		public string GetFocusedRowCellDisplayText()
		{
			return this.grvControl.GetFocusedDisplayText();
		}

		public string GetFocusedDisplayText(string fieldName)
		{
			return this.grvControl.GetFocusedRowCellDisplayText(fieldName);
		}

		public object GetFocusedRowCellValue(string fieldName)
		{
			return this.grvControl.GetFocusedRowCellValue(fieldName);
		}

		public object GetFocusedCellValue()
		{
			return this.grvControl.GetFocusedValue();
		}

		public string GetRowCellDisplayText(int rowHandle, string fieldName)
		{
			return this.grvControl.GetRowCellDisplayText(rowHandle, fieldName);
		}

		public object GetRowCellValue(int rowHandle, string fieldName)
		{
			return this.grvControl.GetRowCellValue(rowHandle, fieldName);
		}

		public int[] GetSelectedRows()
		{
			return this.grvControl.GetSelectedRows();
		}

		public DevExpress.XtraEditors.Repository.RepositoryItem GetRepositoryItem(string name)
		{
			if (!name.StartsWith("repLookUp"))
				name = "repLookUp" + name;
			return this.grdControl.RepositoryItems[name];
		}
		#endregion GETTERS
		//=========================================================================================

		#region grid action
		public void DeleteRow(int rowHandle)
		{
			this.grvControl.DeleteRow(rowHandle);
			this.grvControl.BestFitColumns();
		}

		public void DeleteSelectedRows()
		{
			this.grvControl.DeleteSelectedRows();
			this.grvControl.BestFitColumns();
		}

		public void DeleteRows(int[] rowHandles)
		{
			bool multiSelect = this.grvControl.OptionsSelection.MultiSelect;
			this.grvControl.OptionsSelection.MultiSelect = true;
			foreach (int rowHandle in rowHandles)
				this.grvControl.SelectRow(rowHandle);
			DeleteSelectedRows();
			this.grvControl.OptionsSelection.MultiSelect = multiSelect;
		}

		public void SelectRow(int rowHandle, bool select)
		{
			if (select)
				this.grvControl.SelectRow(rowHandle);
			else
				this.grvControl.UnselectRow(rowHandle);
		}

		public void AddGridColumn(string columnName, string fieldName, string descrition, int index)
		{
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = CreateGridColumn(columnName, fieldName, descrition, index);
			grvControl.Columns.Add(gridColumn);
		}

		public void AddGridColumn(string fieldName, string descrition, int index)
		{
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = CreateGridColumn(fieldName, fieldName, descrition, index);
			grvControl.Columns.Add(gridColumn);
		}

		public void AddGridColumn(string fieldName, string descrition, int index, GridDataType gridDataType, string formatStr)
		{
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = CreateGridColumn(fieldName, fieldName, descrition, index);
			gridColumn.DisplayFormat.FormatType = (gridDataType == GridDataType.DateTime ? DevExpress.Utils.FormatType.DateTime : DevExpress.Utils.FormatType.Numeric);
			if (formatStr == "")
				gridColumn.DisplayFormat.FormatString = (gridDataType == GridDataType.DateTime ? "dd/MM/yyyy" : "n");
			else
				gridColumn.DisplayFormat.FormatString = formatStr;
			grvControl.Columns.Add(gridColumn);
		}

		public void AddGridLookUpEdit(string repLookUpName, string fieldName, string descrition, int index)
		{
			DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit repLookUpEdit = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
			grdControl.RepositoryItems.Add(repLookUpEdit);
			repLookUpEdit.Appearance.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.Appearance.Options.UseFont = true;
			repLookUpEdit.AppearanceDisabled.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.AppearanceDisabled.Options.UseFont = true;
			repLookUpEdit.AppearanceDropDown.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.AppearanceDropDown.Options.UseFont = true;
			repLookUpEdit.AppearanceDropDownHeader.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.AppearanceDropDownHeader.Options.UseFont = true;
			repLookUpEdit.AppearanceFocused.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.AppearanceFocused.Options.UseFont = true;
			repLookUpEdit.AppearanceReadOnly.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.AppearanceReadOnly.Options.UseFont = true;
			repLookUpEdit.AutoHeight = false;
			repLookUpEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo) });
			repLookUpEdit.HideSelection = false;
			repLookUpEdit.Name = "repLookUp" + repLookUpName;
			repLookUpEdit.NullText = "";
			repLookUpEdit.ValueMember = "Key";
			repLookUpEdit.DisplayMember = "Value";
			repLookUpEdit.BestFit();
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = CreateGridColumn(repLookUpName, fieldName, descrition, index);
			gridColumn.ColumnEdit = repLookUpEdit;
			grvControl.Columns.Add(gridColumn);
		}

		public void AddGridLookUpEdit(string fieldName, string descrition, int index)
		{
			DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit repLookUpEdit = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
			grdControl.RepositoryItems.Add(repLookUpEdit);
			repLookUpEdit.Appearance.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.Appearance.Options.UseFont = true;
			repLookUpEdit.AppearanceDisabled.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.AppearanceDisabled.Options.UseFont = true;
			repLookUpEdit.AppearanceDropDown.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.AppearanceDropDown.Options.UseFont = true;
			repLookUpEdit.AppearanceDropDownHeader.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.AppearanceDropDownHeader.Options.UseFont = true;
			repLookUpEdit.AppearanceFocused.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.AppearanceFocused.Options.UseFont = true;
			repLookUpEdit.AppearanceReadOnly.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			repLookUpEdit.AppearanceReadOnly.Options.UseFont = true;
			repLookUpEdit.AutoHeight = false;
			repLookUpEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo) });
			repLookUpEdit.HideSelection = false;
			repLookUpEdit.Name = "repLookUp" + fieldName;
			repLookUpEdit.NullText = "";
			repLookUpEdit.ValueMember = "Key";
			repLookUpEdit.DisplayMember = "Value";
			repLookUpEdit.BestFit();
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = CreateGridColumn(fieldName, fieldName, descrition, index);
			gridColumn.ColumnEdit = repLookUpEdit;
			grvControl.Columns.Add(gridColumn);
		}

		public void AddGridPictureEdit(string repPictureName, string fieldName, string descrition, int index)
		{
			DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit repPicture = new DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit();
			grdControl.RepositoryItems.Add(repPicture);
			repPicture.Appearance.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			repPicture.Appearance.Options.UseFont = true;
			repPicture.AppearanceDisabled.Options.UseFont = true;
			repPicture.AppearanceFocused.Options.UseFont = true;
			repPicture.AppearanceReadOnly.Options.UseFont = true;
			repPicture.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
			repPicture.Name = "repPicture" + repPictureName;
			repPicture.PictureAlignment = System.Drawing.ContentAlignment.MiddleLeft;
			repPicture.PictureStoreMode = DevExpress.XtraEditors.Controls.PictureStoreMode.ByteArray;
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = CreateGridColumn(repPictureName, fieldName, descrition, index);
			gridColumn.ColumnEdit = repPicture;
			grvControl.Columns.Add(gridColumn);
		}

		public void AddGridPictureEdit(string fieldName, string descrition, int index)
		{
			DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit repPicture = new DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit();
			grdControl.RepositoryItems.Add(repPicture);
			repPicture.Appearance.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			repPicture.Appearance.Options.UseFont = true;
			repPicture.AppearanceDisabled.Options.UseFont = true;
			repPicture.AppearanceFocused.Options.UseFont = true;
			repPicture.AppearanceReadOnly.Options.UseFont = true;
			repPicture.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
			repPicture.Name = "repPicture" + fieldName;
			repPicture.PictureAlignment = System.Drawing.ContentAlignment.MiddleLeft;
			repPicture.PictureStoreMode = DevExpress.XtraEditors.Controls.PictureStoreMode.ByteArray;
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = CreateGridColumn(fieldName, fieldName, descrition, index);
			gridColumn.ColumnEdit = repPicture;
			grvControl.Columns.Add(gridColumn);
		}

		public void AddGridCheckBoxEdit(string repCheckEditName, string fieldName, string descrition, int index)
		{
			DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit repCheckEdit = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
			this.grdControl.RepositoryItems.Add(repCheckEdit);
			repCheckEdit.Appearance.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			repCheckEdit.Appearance.Options.UseFont = true;
			repCheckEdit.AppearanceDisabled.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			repCheckEdit.AppearanceDisabled.Options.UseFont = true;
			repCheckEdit.AppearanceFocused.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			repCheckEdit.AppearanceFocused.Options.UseFont = true;
			repCheckEdit.AppearanceReadOnly.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			repCheckEdit.AppearanceReadOnly.Options.UseFont = true;
			repCheckEdit.AutoHeight = false;
			repCheckEdit.AutoWidth = true;
			repCheckEdit.Caption = descrition;
			repCheckEdit.Name = "repCheckEdit" + repCheckEditName;
			repCheckEdit.ValueChecked = true;
			repCheckEdit.ValueUnchecked = false;
			repCheckEdit.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = CreateGridColumn(repCheckEditName, fieldName, descrition, index);
			gridColumn.ColumnEdit = repCheckEdit;
			grvControl.Columns.Add(gridColumn);
		}

		public void AddGridCheckBoxEdit(string fieldName, string descrition, int index)
		{
			DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit repCheckEdit = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
			this.grdControl.RepositoryItems.Add(repCheckEdit);
			repCheckEdit.Appearance.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			repCheckEdit.Appearance.Options.UseFont = true;
			repCheckEdit.AppearanceDisabled.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			repCheckEdit.AppearanceDisabled.Options.UseFont = true;
			repCheckEdit.AppearanceFocused.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			repCheckEdit.AppearanceFocused.Options.UseFont = true;
			repCheckEdit.AppearanceReadOnly.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			repCheckEdit.AppearanceReadOnly.Options.UseFont = true;
			repCheckEdit.AutoHeight = false;
			repCheckEdit.AutoWidth = true;
			repCheckEdit.Caption = descrition;
			repCheckEdit.Name = "repCheckEdit" + fieldName;
			repCheckEdit.ValueChecked = true;
			repCheckEdit.ValueUnchecked = false;
			repCheckEdit.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = CreateGridColumn(fieldName, fieldName, descrition, index);
			gridColumn.ColumnEdit = repCheckEdit;
			grvControl.Columns.Add(gridColumn);
		}

		public void AddGridCheckComboEdit(string repCbkCmbEditName, string fieldName, string columnDesc, int index)
		{
			DevExpress.XtraEditors.Repository.RepositoryItemCheckedComboBoxEdit repChkCmb = new DevExpress.XtraEditors.Repository.RepositoryItemCheckedComboBoxEdit();
			this.grdControl.RepositoryItems.Add(repChkCmb);
			repChkCmb.AutoHeight = false;
			repChkCmb.Name = "repCbkCmbEdit" + repCbkCmbEditName;
			repChkCmb.ValueMember = "Key";
			repChkCmb.DisplayMember = "Value";
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = CreateGridColumn(repCbkCmbEditName, fieldName, columnDesc, index);
			gridColumn.ColumnEdit = repChkCmb;
			grvControl.Columns.Add(gridColumn);
		}

		public void AddGridCheckComboEdit(string fieldName, string columnDesc, int index)
		{
			DevExpress.XtraEditors.Repository.RepositoryItemCheckedComboBoxEdit repChkCmb = new DevExpress.XtraEditors.Repository.RepositoryItemCheckedComboBoxEdit();
			this.grdControl.RepositoryItems.Add(repChkCmb);
			repChkCmb.AutoHeight = false;
			repChkCmb.Name = "repCbkCmbEdit" + fieldName;
			repChkCmb.ValueMember = "Key";
			repChkCmb.DisplayMember = "Value";
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = CreateGridColumn(fieldName, fieldName, columnDesc, index);
			gridColumn.ColumnEdit = repChkCmb;
			grvControl.Columns.Add(gridColumn);
		}

		public void AddColumnGroup(string fieldName)
		{
			this.grvControl.SortInfo.Add(new DevExpress.XtraGrid.Columns.GridColumnSortInfo(this.grvControl.Columns[fieldName], DevExpress.Data.ColumnSortOrder.Ascending));
			this.grvControl.GroupCount++;
		}

		public void RemoveColumnGroup(string fieldName)
		{
			this.grvControl.SortInfo.Remove(this.grvControl.Columns[fieldName]);
			this.grvControl.GroupCount--;
		}

		public void AddSummaryColumn(string fieldName)
		{
			this.grvControl.Columns[fieldName].SummaryItem.FieldName = fieldName;
			this.grvControl.Columns[fieldName].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom;
			this.grvControl.OptionsView.ShowFooter = true;
		}

		public void RemoveSummaryColumn(string fieldName)
		{
			this.grvControl.Columns[fieldName].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.None;
		}
		#endregion grid action
		//=========================================================================================

		#region grid events
		private void grvControl_MouseDown(object sender, MouseEventArgs e)
		{
			Point hitPoint = this.grdControl.PointToClient(Control.MousePosition);
			DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hitInfo = this.grvControl.CalcHitInfo(hitPoint);
			if (e.Clicks == 1 && hitInfo.InColumn)
			{
				if (this.sortColumn == hitInfo.Column.FieldName)
					this.orderByExpression = (this.orderByExpression == "ASC" ? "DESC" : "ASC");
				else
				{
					this.sortColumn = hitInfo.Column.FieldName;
					this.orderByExpression = "ASC";
				}
				if (OnInColumn_Click != null)
					OnInColumn_Click(sender, null);
			}
			else
				if (e.Clicks == 2)
				{
					if (hitInfo.InRow)
					{
						if (OnRow_DoubleClick != null)
							OnRow_DoubleClick(sender, null);
					}
					else
						if (hitInfo.InGroupColumn)
						{
							if (OnGroupColumn_DoubleClick != null)
								OnGroupColumn_DoubleClick(sender, null);
						}
						else
							if (!hitInfo.InColumn && !hitInfo.InColumnPanel && !hitInfo.InFilterPanel && !hitInfo.InGroupPanel)
							{
								if (OnEmptyArea_DoubleClick != null)
									OnEmptyArea_DoubleClick(sender, null);
							}
				}
		}

		private void grvControl_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
		{
			if (OnFocusedRowChanged != null)
				OnFocusedRowChanged(sender, e);
		}
		#endregion grid events
		//=========================================================================================

		#region private functions
		private DevExpress.XtraGrid.Columns.GridColumn CreateGridColumn(string columnName, string fieldName, string description, int index)
		{
			DevExpress.XtraGrid.Columns.GridColumn gridColumn = new DevExpress.XtraGrid.Columns.GridColumn();
			gridColumn.AppearanceHeader.Font = new Font("Tahoma", 8.25F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0)));
			gridColumn.AppearanceHeader.Options.UseFont = true;
			gridColumn.AppearanceCell.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
			gridColumn.AppearanceCell.Options.UseFont = true;
			gridColumn.Caption = description;
			gridColumn.FieldName = fieldName;
			gridColumn.Name = "cl" + columnName;
			gridColumn.OptionsColumn.AllowEdit = false;
			gridColumn.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.False;
			gridColumn.OptionsColumn.AllowMove = false;
			gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
			gridColumn.BestFit();
			gridColumn.VisibleIndex = index;
			return gridColumn;
		}
		#endregion private functions
		//=========================================================================================
	}
}
